//
//  FoodDatilViewController.m
//  HealthA段
//
//  Created by MrJXT on 15/6/4.
//  Copyright (c) 2015年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FoodDatilViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+WebCache.h"
@interface FoodDatilViewController ()<UITableViewDataSource,UITableViewDelegate,UIWebViewDelegate>
@property(nonatomic,retain)UITableView *foodtable;
@property(nonatomic,retain)NSMutableArray *Arr;
@property(nonatomic,retain)NSMutableDictionary *foodDic;
@property(nonatomic,copy)NSString *Foodsource;

@end

@implementation FoodDatilViewController
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.Arr = [NSMutableArray array];
        self.foodDic = [NSMutableDictionary dictionary];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;

    
    [self creatView];
    [self PleaseData];
}
//试图创建
-(void)creatView
{
    self.foodtable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
    
    self.foodtable.delegate = self;
    self.foodtable.dataSource =self;
    
    self.foodtable.rowHeight = HEIGHT;
    
    [self.view addSubview:self.foodtable];
    
    [_foodtable release];
}

//协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    FoosDatilCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        cell = [[[FoosDatilCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
    }
    NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.foodDic objectForKey:@"img"]];
    NSURL *url = [NSURL URLWithString:str];
    [cell.picView sd_setImageWithURL:url];
    NSString *strMeth = [NSString stringWithFormat:@"做法：%@",[self.foodDic objectForKey:@"message"]];
    cell.methLabel.text = strMeth;
    NSString *strFood = [NSString stringWithFormat:@"食材:%@",[self.foodDic objectForKey:@"food"]];
    cell.foodLabel.text = strFood;
    NSString *strTag = [NSString stringWithFormat:@"标签:%@",[self.foodDic objectForKey:@"tag"]];
    cell.tagLabel.text = strTag;
    return cell;
}

//请求数据
-(void)PleaseData
{
    NSString *url = [NSString stringWithFormat:@"http://api.yi18.net/cook/show?id=%ld",(long)self.id];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        self.foodDic = [dic objectForKey:@"yi18"];
//        FoodDatil *f = [[FoodDatil alloc]init];
//        [f setValuesForKeysWithDictionary:Dic];
//        [self.Arr addObject:f];
//        [f release];
        [self.foodtable reloadData];
//        NSLog(@"-----%@",f.food);
        NSLog(@"aaa  ===%ld",self.id);
        NSLog(@"yyyy%@",[self.foodDic objectForKey:@"message"]);
        NSLog(@"gggg===%@",[self.foodDic objectForKey:@"count"]);
        NSLog(@"hhhh%@",[self.foodDic objectForKey:@"food"]);
        NSLog(@"xxxxx%@",[self.foodDic objectForKey:@"tag"]);
        self.Foodsource = [self.foodDic objectForKey:@"message"];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"数据请求失败");
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
